package com.itstu.controller;

import com.itstu.annotaion.LoginUser;
import com.itstu.model.AjaxResult;
import com.itstu.pojo.Friend;
import com.itstu.pojo.User;
import com.itstu.service.FriendService;
import com.itstu.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 梁卓
 * @Version 1.0
 * @ClassName FriendController
 * @Description TODO
 * @Date 2024/10/08 20:37
 */
@RestController
@RequestMapping("/friend")
public class FriendController {

    @Resource
    private FriendService friendService;

    /**
     * 查询好友列表
     * @param user 登录用户信息
     * @return 好友列表
     */
    @GetMapping
    public AjaxResult getFriendList(@LoginUser User user) {
        List<User> resultList = friendService.getFriendList(user.getId());
        return AjaxResult.success(resultList);
    }

    /**
     * 判断是否为好友
     * @param friend 好友信息
     * @return true为好友，false为不是好友
     */
    @PostMapping("/hasFriend")
    public AjaxResult hasFriend(@LoginUser User user, @RequestBody Friend friend) {
        friend.setUid(user.getId());
        boolean result = friendService.hasFriend(friend);
        return AjaxResult.success(result);
    }
}
